package com.boc.bus.control;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.boc.bus.factory.AbstractFactory;

public class ControlBus {
	public ControlBus() {

	}

	public Object invokeFactoryProxyClass(HttpServletRequest request,
			HttpServletResponse response, Class proxyed)
			throws SecurityException, NoSuchMethodException,
			IllegalArgumentException, IllegalAccessException,
			InvocationTargetException, InstantiationException {

		Method method = AbstractFactory.class.getMethod("invoke", new Class[] {
				HttpServletRequest.class, HttpServletResponse.class });
		return method.invoke(proxyed.newInstance(), new Object[] { request,
				response });
	}

	public Object invokeFactoryProxyClass(HttpServletRequest request,
			HttpServletResponse response, Map m, Class proxyed, String reqCode)
			throws SecurityException, NoSuchMethodException,
			IllegalArgumentException, IllegalAccessException,
			InvocationTargetException, InstantiationException {

		Method method = proxyed.getMethod(reqCode,
				new Class[] { HttpServletRequest.class,
						HttpServletResponse.class, Map.class });
		return method.invoke(proxyed.newInstance(), new Object[] { request,
				response, m });
	}
}
